package com.it.web.controller;


import com.it.model.User;
import com.it.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

/**
 * @ClassName HelloController
 * @Author shuyy
 * @Date 2020/10/25
 **/
@Controller
@RequestMapping("user")
public class UserController {

    @Autowired
    private UserService userService;

    @RequestMapping("register")
    @ResponseBody
    public String register(String username,String password){

        userService.register(username,password);
        return "success";
    }

    @RequestMapping("findUser")
    @ResponseBody
    public User findUser(Integer id){
        return userService.findUserById(id);
    }

    @RequestMapping("findUserList")
    public String findUserList(Model model){
        model.addAttribute("username","shu");
        model.addAttribute("age",20);
        model.addAttribute("sex","男");
        List<User> userList = userService.findUserList();
        model.addAttribute("userList",userList);
        return "/user/list";
    }
}
